package ink.yql.dao;

import ink.yql.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

@Mapper
public interface UserDao {
    /**
     * @param phone 手机号
     * @param pwd   密码
     * @return 用户
     * <p>
     * 根据手机号和密码查询用户
     */
    @Select("select * from user where uphone = #{phone} and upwd = #{pwd}")
    User getByPhoneAndPwd(@Param("phone") String phone, @Param("pwd") String pwd);

    /**
     * @param uloginTime 最后登录的时间
     * @param uloginIp   最后登录的ip
     * @param uid        用户id
     * @return 影响行数
     * <p>
     * 记录用户最后一次登录的信息
     */
    @Update("update user set uloginTime = #{uloginTime} , uloginIp = #{uloginIp} where uid = #{uid}")
    Integer updateLoginTimeAndIp(@Param("uloginTime") Date uloginTime, @Param("uloginIp") String uloginIp,
                                 @Param("uid") Integer uid);

    /**
     * @param phone 手机号
     * @return 用户
     * 根据手机号查询用户
     */
    @Select("select * from user where uphone = #{phone}")
    User getByPhone(@Param("phone") String phone);

    /**
     * @param uid 用户id
     * @return 用户
     * 通过id查询用户
     */

    @Select("select * from user where uid = #{uid} ")
    User getByUid(@Param("uid") Integer uid);

    @Update("update user set usummary = #{usummary} ,usex=#{usex},ubirthday=#{ubirthday},uprovince=#{uprovince}," +
              "ucity=#{ucity},uaddress=#{uaddress} where uid=#{uid}")
    Integer updateByUid(User daoByUid);

    /**
     *
     * @param uattentionCount 关注人数
     * @param uid   用户id
     * @return  影响行数
     */
    @Update("update user set uattentionCount = uattentionCount+#{uattentionCount} where uid = #{uid}")
    Integer updateUattentionCount(@Param("uattentionCount") Integer uattentionCount, @Param("uid") Integer uid);
    /**
     *
     * @param ufansCount 粉丝数
     * @param uid   用户id
     * @return  影响行数
     */
    @Update("update user set ufansCount = ufansCount+#{ufansCount} where uid = #{uid}")
    Integer updateUfansCount(@Param("ufansCount") Integer ufansCount, @Param("uid") Integer uid);
    /**
     *
     * @param uintegral 积分
     * @param uid   用户id
     * @return  影响行数
     */
    @Update("update user set uintegral = uintegral+#{uintegral} where uid = #{uid}")
    Integer updateUintegral(@Param("uintegral") Integer uintegral, @Param("uid") Integer uid);

}
